import request from '@/utils/request'

//短信验证码
// export function smsCode(mobile, timestamp, imageCode, msgType) {
//   let data = qs.stringify({
//     mobilePhone: mobile,
//     timestamp,
//     imageCode,
//     msgType
//   })
//   return request({
//     url: `/oauth/smsAuthCode`,
//     method: 'post',
//     headers: {
//       'Content-Type': 'application/x-www-form-urlencoded'
//     },
//     data
//   })
// }

//  获取 openId
export function wxOpenId(data = {}) {
  return request({
    url: '/oauth/wxOpenId',
    method: 'post',
    data
  })
}

//是否首次登陆 - 防止跳转到编辑界面
export function isFirstLogin(data = {}) {
  return request({
    url: '/spgl/SpdbParent/isFirstLogin',
    method: 'post',
    data
  })
}

//登录
export function wxLogin(data = {}) {
  return request({
    url: '/oauth/Login',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data
  })
}

export function wxlogin(data = {}) {
  return request({
    url: '/oauth/Login',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data
  })
}



//退出登录
export function logOut() {
  return request({
    url: '/oauth/Logout',
    method: 'get'
  })
}

//  获取微信 js 接口临时票据
export function getTicket(data = {}) {
  return request({
    url: '/oauth/getTicket',
    method: 'post',
    data
  })
}


// 获取微信用户code  
export function wxEmpower(path = '') {
  let appid = process.env.VITE_APP_API_APPID;
  let base_url = process.env.VITE_APP_API_HOST;
  let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(base_url + path)}&response_type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect`;
  //  页面跳转
  location.href = url;
}